package com.huawei.fakedouyin.util

import android.util.Log

/**
 * @author: WangYT
 * @date: {2023/2/3 10:26}
 * @remake:
 */
class LogUtil {
    companion object {
        val Instance by lazy { LogUtil() }
    }

    fun logDebug(msg: Any?) {
        Log.d(buildTag(), buildMsg(msg))
    }

    fun logError(msg: Any?) {
        Log.e(buildTag(), buildMsg(msg))
    }

    /**
     * 构建TAG：FatAn+类名+方法名+线程
     */
    private fun buildTag(): String {
        buildString {
            append("FatAnBase")
            val stack = Throwable().fillInStackTrace().stackTrace
            for (item in stack) {
                if (item.isNativeMethod) continue
                if (item.className == LogUtil::class.java.name) continue
                if (item.className.contains(".UtilKt")) continue
                if (item.className.contains("LogUtil")) continue
                if (item.className == Thread::class.java.name) continue
                append("(")
                append(item.fileName)
                append(":")
                append(item.lineNumber)
                append(")")
                append("[")
                append(Thread.currentThread().name)
                append("]")
                return toString()
            }

        }
        return "TAG"
    }

    /**
     * 将日志信息标重
     * @return String
     */
    private fun buildMsg(msg: Any?): String {
        return msg.toString()
//        buildString {
//            appendLine(" ")
//            appendLine("╔═══════════════════════════════════════════════════════════════════════════════════════════════════")
//            append("║ ")
//            appendLine(msg)
//            appendLine("╚═══════════════════════════════════════════════════════════════════════════════════════════════════")
//            return toString()
//        }
    }
}

fun logDebug(msg: Any?) {
    LogUtil.Instance.logDebug(msg)
}

fun logError(msg: Any?) {
    LogUtil.Instance.logDebug(msg)
}